package com.example.w_library.log.base;

import com.example.w_library.log.priter.WLogPrinter;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 日志管理类-初始化相关
 */
public class WLogManager {

    private WLogConfig config;

    //打印器数组
    private List<WLogPrinter> printers = new ArrayList<>();

    private static WLogManager instance;

    private WLogManager(WLogConfig config,WLogPrinter[] printers){
        this.config = config;
        this.printers.addAll(Arrays.asList(printers));
    }

    public static WLogManager getInstance(){
        return instance;
    }

    /**
     * 初始化
     * @param config 日志配置类
     * @param printers 可变类型打印器参数
     */
    public static void init(@NotNull WLogConfig config,WLogPrinter... printers){
        instance = new WLogManager(config,printers);
    }

    /**
     * 获取日志配置类
     * @return
     */
    public WLogConfig getConfig(){
        return config;
    }

    /**
     * 获取日志打印器集合
     * @return
     */
    public List<WLogPrinter> getPrinters(){
        return printers;
    }

    /**
     * 添加日志打印器
     * @param logPrinter
     */
    public void addPrinter(WLogPrinter logPrinter){
        printers.add(logPrinter);
    }

    /**
     * 日出日志打印器
     * @param logPrinter
     */
    public void removePrinter(WLogPrinter logPrinter){
        if (printers != null){
            printers.remove(logPrinter);
        }
    }
}
